package com.holyn.guofang.presenter.web;

import com.holyn.guofang.model.webhttp.RetrofitManager;
import com.holyn.guofang.model.webhttp.observable.OnlineServiceObservable;
import com.holyn.guofang.model.webhttp.wo.ServiceTypeWo;
import com.holyn.guofang.model.webhttp.wo.StatusWo;
import com.holyn.guofang.presenter.BaseView;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by Holyn on 2017/7/30.
 */

public class WebPresenter extends WebContract.Presenter{

    private OnlineServiceObservable onlineServiceObservable;
    private WebContract.WebView webView;

    public WebPresenter(BaseView baseView) {
        super(baseView);
        onlineServiceObservable = RetrofitManager.getCommonObservable(OnlineServiceObservable.class);
    }

    @Override
    public void addWebViewListener(WebContract.WebView webView) {
        this.webView = webView;
    }

    @Override
    public void postListServiceType(int requestAction, String code, Integer parentID, Integer grade) {
        getCommonObservable(requestAction, onlineServiceObservable.listServiceType(code, parentID, grade))
                .subscribe(new Consumer<ServiceTypeWo>() {
                    @Override
                    public void accept(@NonNull ServiceTypeWo serviceTypeWo) throws Exception {
                        webView.responseSuccess(requestAction, serviceTypeWo);
                    }
                });
    }

    @Override
    public void postAddTradeMarkTrust(int requestAction, Integer id, Integer serviceID, String content, String company, String contact, String QQ, String telephone, String email) {
        getCommonObservable(requestAction, onlineServiceObservable.addTradeMarkTrust(id, serviceID, content, company, contact, QQ, telephone, email))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        webView.responseSuccess(requestAction, statusWo);
                    }
                });
    }
}
